Skip to content

Conversation

@himanshupathak95
Copy link

@himanshupathak95 himanshupathak95 commented Mar 28, 2025

Trac ticket: https://core.trac.wordpress.org/ticket/63186

This PR addresses the issue where empty properties arrays in REST API JSON schemas are output as [] instead of {}.

According to JSON Schema specifications, the properties field must always be an object. However, when a REST API schema in PHP uses 'properties' => array(), it gets JSON-encoded as "properties": [], which is an invalid JSON schema.

This PR adds a sanitization function that recursively processes REST API schema data and converts any empty properties arrays to empty objects (using stdClass), ensuring valid JSON schema output. The fix is minimal and targeted, applied via a filter at the appropriate stage of REST API response processing.

@github-actions
Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@himanshupathak95 himanshupathak95 marked this pull request as ready for review April 2, 2025 08:12
@github-actions
Copy link

github-actions bot commented Apr 2, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props abcd95, flixos90, westonruter.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@himanshupathak95 himanshupathak95 force-pushed the fix/63186-empty-properties-json-schema branch from 9308318 to b7fad5c Compare April 2, 2025 08:54
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@himanshupathak95 Thank you for the PR!

The sanitizer function looks great. I think there's one problem to figure out though regarding when to call it.

@himanshupathak95 himanshupathak95 force-pushed the fix/63186-empty-properties-json-schema branch from b7fad5c to d4af322 Compare November 20, 2025 14:22
@himanshupathak95 himanshupathak95 force-pushed the fix/63186-empty-properties-json-schema branch 2 times, most recently from 3b5b3b2 to bb75e9a Compare November 28, 2025 13:52
@himanshupathak95 himanshupathak95 force-pushed the fix/63186-empty-properties-json-schema branch from bb75e9a to f57bee4 Compare December 6, 2025 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants